<template>
  <div class="app-container-sm">
      <el-card class="card-margin-bottom">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" class="form-minus-bottom">
      <el-form-item label="溯源码" prop="traceCode">
        <el-input
          v-model="queryParams.traceCode"
          placeholder="请输入溯源码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="查询时间">
        <el-date-picker
          v-model="daterangeQueryDate"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="查询地点" prop="queryAddress">
        <el-input
          v-model="queryParams.queryAddress"
          placeholder="请输入查询地点"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="查询坐标" prop="queryCoordinate">
        <el-input
          v-model="queryParams.queryCoordinate"
          placeholder="请输入查询坐标"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
        <el-form-item class="fr">
            <el-button
                    type="warning"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    @click="handleExport"
                    v-hasPermi="['agriculture:record:export']"
            >导出</el-button>
        </el-form-item>
    </el-form>
      </el-card>
<el-card class="card-padding-bottom">
    <el-table v-loading="loading" :data="recordList" >
      <el-table-column label="溯源码" align="center" prop="traceCode" />
      <el-table-column label="查询时间" align="center" prop="queryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.queryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="城市" align="center" prop="queryCity" />
      <el-table-column label="详细地址" align="center" prop="queryAddress" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
</el-card>
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/trace/record";

export default {
  name: "",
  data() {
    return {
      // 遮罩层
      loading: true,
      showSearch: true,
      // 总条数
      total: 0,
      // 溯源码查询记录表格数据
      recordList: [],
      // 查询坐标时间范围
      daterangeQueryDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        traceCode: null,
        queryDate: null,
        queryAddress: null,
        queryCoordinate: null,
      }
    };
  },
  created() {
    this.queryParams.traceCode = this.$route.query.traceCode;
    this.getList();
  },
  methods: {
    /** 查询溯源码查询记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeQueryDate && '' != this.daterangeQueryDate) {
        this.queryParams.params["beginQueryDate"] = this.daterangeQueryDate[0];
        this.queryParams.params["endQueryDate"] = this.daterangeQueryDate[1];
      }
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeQueryDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('agriculture/record/export', {
        ...this.queryParams
      }, `record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
